<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>注册</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="alternate icon" type="image/png" href="assets/i/favicon.png">
  <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
  <style>
    .header {
      text-align: center;
    }
    .header h1 {
      font-size: 200%;
      color: #333;
      margin-top: 30px;
    }
    .header p {
      font-size: 14px;
    }
  </style>
  <script type="text/javascript" src="assets/js/jquery.min.js"></script>
  <script type="text/javascript">
  
  function loadPicimageCode() {
	 
	document.getElementById("picimageCode").src = 'image_code?ran=' + Math.random();
	  
	}

  function regist() {

			if($('[name="model.email"]').val()==''){
				alert('邮箱不能为空！');
				return;
			}
			/* else{
				 var reg = "/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/";				
				 isok= reg.test($('[name="model.email"]').val());
				 if (!isok) {			
				             alert("邮箱格式不正确，请重新输入！");
				             document.getElementById("email").focus();
				             return; 
				             }
			} */
			if($('[name="model.realname"]').val()==''){
				alert('昵称不能为空！');
				return;
			}
			var pwd = $('[name="password"]').val();
			var pwd2 = $('[name="password2"]').val();
			if(pwd==''){
				alert('密码不能为空！');
				return;
			}
			if(pwd2==''){
				alert('确认密码不能为空！');
				return;
			}
			if(pwd.length < 6 ){
				alert('密码长度必须大于等于6');
				return;
			}
			if(pwd != pwd2){
				alert('两次密码不一致！');
				return;
			}
			if($('[name="imageCode"]').val()==''){
				alert('验证码不能为空！');
				return;
			}
			
			jQuery.ajax({
				type:'POST',
				url:'regist',
				data:$("form").serialize(),
				success:function(data){
					if(data.status==1){
						alert('保存成功');
						var prePage = $('[name="pre_page"]').val();
						if (prePage=='') {
							prePage = "/";
						}
						window.top.location.href = prePage;
					} else {
						loadPicimageCode();
						$('[name="imageCode"]').val('');
						$('[name="password"]').val('');
						$('[name="password2"]').val('');
						alert('保存失败：'+data.msg);
					}
				},
				error:function(html){
					var flag = (typeof console != 'undefined');
					if(flag) console.log("服务器忙，提交数据失败，代码:" +html.status+ "，请联系管理员！");
					alert("服务器忙，提交数据失败，请联系管理员！");
				}
			});
	
	}
  </script>
</head>
<body>
<div class="header">
  <div class="am-g">
    <h1>注册 </h1>
    <p>按提示填写你的信息<br/>本产品保证保护隐私请放心使用</p>
  </div>
  <hr />
</div>
<div class="am-g">
  <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
       
 
    <form  name = "form1" method="post" class="am-form">
      <label for="email">邮箱:</label>
      <input type="email" name="user.email" id="email" value="">
      <br>
      <label for="realname">昵称:</label>
      <input type="text" name="user.realname" id="email" value="">
      <br>
      <label for="password">密码:</label>
      <input type="password" name="password" id="password" value="">
      <br>
      <label for="password2">重复密码:</label>
      <input type="password" name="password2" id="password2" value="">
      <br>
     <label for="imageCode" class="col-sm-2 control-label">验证码：</label>
	
	<div class="am-g">
    <div class="am-u-sm-10"><input name="imageCode" type="text"  class="form-control" id="imageCode" 
							tabindex="1" placeholder="验证码"></div>
  
    <div class="am-u-sm-2"> <img id="picimageCode" align="middle" width="60" height="40"  
	  style="line-height: 18px;cursor:pointer;"
		 src="image_code" title="更换一张验证码图片" onclick="loadPicimageCode()"/></div>
   </div>

      <br>
     
      <br />
      <div class="am-cf">
        <input type="submit" name="" value="注册" class="am-btn am-btn-primary am-btn-sm am-fl"  onclick="regist();">
        <input type="reset" name="" value="重置" class="am-btn am-btn-primary am-btn-sm am-fr" >
      </div>
    </form>
    <hr>
   
  </div>
</div>
</body>
</html>